Skip to content

Add BPF_F_NO_MAX_ENTRIES option for map creation - #5543

Open
Anurag Saxena (saxena-anurag) wants to merge 11 commits into
mainfrom
user/anusa/issue_5520
Open

Add BPF_F_NO_MAX_ENTRIES option for map creation#5543
Anurag Saxena (saxena-anurag) wants to merge 11 commits into
mainfrom
user/anusa/issue_5520

Conversation

@saxena-anurag

@saxena-anurag Anurag Saxena (saxena-anurag) commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Closes #5520

Description

PR #3348 allowed hash-table-based maps to exceed max_entries, treating it only as an initial bucket-count hint. This differs from Linux behavior and means the declared map size does not bound memory usage.

This change restores bounded behavior by default and adds a Windows only BPF_F_NO_MAX_ENTRIES for applications that explicitly require unbounded maps.

The flag is supported for:

  • BPF_MAP_TYPE_HASH
  • BPF_MAP_TYPE_PERCPU_HASH
  • BPF_MAP_TYPE_HASH_OF_MAPS
  • BPF_MAP_TYPE_LPM_TRIE

LRU maps retain their existing bounded eviction behavior. Unsupported map types and unknown flags are rejected.

The flag is propagated through map creation, ELF definitions, map information queries, the core protocol, and bpf2c-generated native metadata. Legacy native metadata remains supported, with missing flags defaulting to zero.

The exported ebpf_map_info_t layout remains unchanged so applications built against older versions of ebpfapi.dll can safely use arrays returned by ebpf_api_get_pinned_map_info.

Testing

Added unit and end-to-end coverage for bounded and unbounded map behavior, map creation through libbpf and JIT/native programs, native metadata compatibility, and the ebpf_map_info_t ABI. Updated generated bpf2c expected output.

Documentation

No documentation changes.

Installation

No installer changes.

@saxena-anurag Anurag Saxena (saxena-anurag) changed the title [draft] add map flag Enforce hash map entry limits by default Sep 12, 2026
@saxena-anurag Anurag Saxena (saxena-anurag) changed the title Enforce hash map entry limits by default Add BPF_F_NO_MAX_ENTRIES option for map creation Sep 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Three critical map-flag propagation and native map-reuse validation issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds Windows-only BPF_F_NO_MAX_ENTRIES support while restoring bounded map behavior by default.

Changes:

  • Propagates map flags through APIs, ELF/BTF, native metadata, protocols, and map information.
  • Adds bounded/unbounded map samples and compatibility coverage.
  • Updates generated bpf2c expectations.
File summaries
File Change
tools/bpf2c/bpf_code_generator.cpp Emits map flags in native metadata.
tests/sample/undocked/map_synchronized_update.c Updates sample map configuration.
tests/sample/undocked/map_no_max_entries.c Adds unbounded-map sample.
tests/sample/undocked/map_max_entries.c Adds bounded-map sample.
tests/bpf2c_tests/expected/thread_start_time_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/thread_start_time_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/thread_start_time_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/test_utility_helpers_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/test_utility_helpers_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/test_utility_helpers_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_redirect_map_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_redirect_map_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_redirect_map_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_perf_event_array_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_perf_event_array_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_perf_event_array_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_implicit_helpers_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_implicit_helpers_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_implicit_helpers_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_ebpf_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_ebpf_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/test_sample_ebpf_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/test_invalid_redirect_map_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/test_invalid_redirect_map_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/test_invalid_redirect_map_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_sequential_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_sequential_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_sequential_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_same_section_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_same_section_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_same_section_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_recursive_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_recursive_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_recursive_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_multiple_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_multiple_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_multiple_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_max_exceed_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_max_exceed_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_max_exceed_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_map_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_map_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_map_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_bad_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_bad_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/tail_call_bad_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/sockops_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/sockops_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/sockops_flow_id_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/sockops_flow_id_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/sockops_flow_id_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/sockops_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/process_start_key_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/process_start_key_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/process_start_key_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/pidtgid_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/pidtgid_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/pidtgid_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/perf_event_cpu_target_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/perf_event_cpu_target_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/perf_event_cpu_target_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/perf_event_burst_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/perf_event_burst_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/perf_event_burst_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_synchronized_update_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_synchronized_update_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_synchronized_update_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_sequential_lookup_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_sequential_lookup_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_sequential_lookup_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_reuse_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_reuse_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_reuse_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_reuse_2_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_reuse_2_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_reuse_2_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_legacy_idx_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_legacy_idx_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_legacy_idx_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_legacy_id_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_legacy_id_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_legacy_id_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_btf_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_btf_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_in_map_btf_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/map_annotation_collision_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/map_annotation_collision_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/map_annotation_collision_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/lru_map_test_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/lru_map_test_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/lru_map_test_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/hash_of_map_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/hash_of_map_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/hash_of_map_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/global_vars_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/global_vars_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/global_vars_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/global_vars_and_map_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/global_vars_and_map_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/global_vars_and_map_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/droppacket_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/droppacket_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/droppacket_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/divide_by_zero_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/divide_by_zero_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/divide_by_zero_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/custom_map_invalid_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/custom_map_invalid_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/custom_map_invalid_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_sock_addr_bind_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_sock_addr_bind_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_count_connect6_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_count_connect6_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_count_connect6_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_count_connect4_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_count_connect4_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_count_connect4_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_connect_authorization6_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_connect_authorization6_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/cgroup_connect_authorization6_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/callgraph_bpf2bpf_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/callgraph_bpf2bpf_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/callgraph_bpf2bpf_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bpf2bpf_loop_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bpf2bpf_loop_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bpf2bpf_loop_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bpf_call_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bpf_call_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bpf_call_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_ringbuf_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_ringbuf_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_ringbuf_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_perf_event_array_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_perf_event_array_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_perf_event_array_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_mt_tailcall_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_mt_tailcall_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_mt_tailcall_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bindmonitor_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bind_policy_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bind_policy_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bind_policy_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/bad_map_name_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/bad_map_name_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/bad_map_name_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/atomic_instruction_fetch_add_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/atomic_instruction_fetch_add_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/atomic_instruction_fetch_add_dll.c Updates generated expectation.
tests/bpf2c_tests/expected/ambiguous_array_map_sys.c Updates generated expectation.
tests/bpf2c_tests/expected/ambiguous_array_map_raw.c Updates generated expectation.
tests/bpf2c_tests/expected/ambiguous_array_map_dll.c Updates generated expectation.
libs/shared/user/shared_user.vcxproj.filters Updates project file entries.
libs/shared/user/shared_user.vcxproj Updates project file entries.
libs/shared/kernel/shared_kernel.vcxproj.filters Updates project file entries.
libs/shared/kernel/shared_kernel.vcxproj Updates project file entries.
libs/shared/ebpf_serialize.c Supports map metadata serialization.
libs/shared/ebpf_native_structs.h Updates native metadata structures.
libs/service/api_service.cpp Propagates map information.
libs/runtime/unit/platform_unit_test.cpp Updates platform coverage.
libs/ioctl_spec/generated/EbpfProtocol.h Updates protocol definitions.
libs/ioctl_spec/EbpfProtocol.3d Updates protocol layout.
libs/ioctl_spec/ebpf_protocol_layout_check.h Updates layout checks.
libs/api/windows_platform.cpp Handles legacy map flags.
libs/api/Verifier.cpp Parses and caches map metadata.
libs/api_common/map_descriptors.hpp Extends map descriptors.
libs/api_common/map_descriptors.cpp Implements map descriptor flags.
libs/api_common/api_common.hpp Updates common map definitions.
include/linux/bpf.h Extends map creation and information structures.
include/ebpf_structs.h Defines map flags and metadata.
include/ebpf_core_structs.h Preserves map-info ABI layout.
include/bpf2c.h Extends native map metadata.
Review details
  • Files reviewed: 210/212 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread libs/api/Verifier.cpp
btf_map_descriptor.key_size,
btf_map_descriptor.value_size,
btf_map_descriptor.max_entries,
0,
map_definition.key_size = native_map->entry.definition.key_size;
map_definition.value_size = native_map->entry.definition.value_size;
map_definition.max_entries = native_map->entry.definition.max_entries;
map_definition.map_flags = native_map->entry.map_flags;
output_stream << INDENT " " << std::left << std::setw(stream_width) << name.quoted() + "," << "// Map name."
<< std::endl;
output_stream << INDENT " " << std::left << std::setw(stream_width)
<< std::to_string(entry.definition.map_flags) + "," << "// Map creation flags." << std::endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Add BPF_F_NO_MAX_ENTRIES option for map creation

2 participants